<?php
/**
 * Created by PhpStorm.
 * User: win7
 * Date: 2018/6/2 0002
 * Time: 15:33
 */

namespace XtwsBack\Controller;

use Think\Controller;

class RepetitionQrcodeController extends Controller
{

    //支付牌二维码生成
    public function index(){
        $op = $_POST['op'] ? $_POST['op']:'display';

        if ($op == 'create'){
            $pay = M("shop_pay")->select();
            $allqrcode = array();
            $num = 0;

            foreach ($pay as $k => $v){
                if (empty($v['qrcode'])){
                    $qrcode = D("Qrcode")->Qrcode($v['s_id'],$v['u_id']);
                    if ($qrcode){
                        $add_qrcode = M("shop_pay")->where("id = {$v['id']}")->save(['qrcode'=>$qrcode]);
                        if ($add_qrcode){
                            $num += 1;
                            $success = $num;
                            $allqrcode[]=['id' => $v['id'],'state'=>'成功'];
                        }else{
                            $num += 1;
                            $error = $num;
                            $allqrcode[]= ['id' => $v['id'],'state'=>'失败'];
                        }//end if
                    }//end if
                }//end if
            }//end foreach

            $this->assign('error',$error);
            $this->assign('success',$success);
            $this->assign('allqrcode',$allqrcode);

        }//end if

        $this->display();
    }//end fun
}//end class